﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/// <summary>
/// 
/// </summary>
namespace 飞行棋
{
    class Program
    {
        //用静态字段来模拟全局变量
        static int[] Maps = new int[100];
        //声明一个静态数组来存储玩家A和玩家B的坐标
        static int[] PlayerPos = new int[2];
        //存储两个玩家的姓名
        static string[] PlayerNames = new string[2];

        static void Main(string[] args)
        {
            //1.画游戏头
            //2.初始化地图（加载地图所需要的资源）
            //将整数数组中的数字编成控制台中显示的特殊字符串的过程--初始化地图
            //3.画地图
            //4.玩游戏
            GameShow();
            #region 玩家姓名输入
            Console.WriteLine("请输入玩家A的姓名");
            PlayerNames[0] = Console.ReadLine();
            while (PlayerNames[0] == "")
            {
                Console.WriteLine("玩家A的姓名不能为空，请重新输入");
                PlayerNames[0] = Console.ReadLine();
            }

            Console.WriteLine("请输入玩家B的姓名");
            PlayerNames[1] = Console.ReadLine();
            while (PlayerNames[1] == "" || PlayerNames[1] == PlayerNames[0])
            {
                if (PlayerNames[1] == "")
                {
                    Console.WriteLine("玩家B的姓名不能为空，请重新输入");
                    PlayerNames[1] = Console.ReadLine();
                }
                else
                {
                    Console.WriteLine("玩家B的姓名不能和玩家A的姓名相同，请重新输入");
                    PlayerNames[1] = Console.ReadLine();
                }
            }
            #endregion

            //玩家输入姓名OK后，首先应该清屏
            Console.Clear();//清屏
            GameShow();
            Console.WriteLine("{0}的士兵用A表示", PlayerNames[0]);
            Console.WriteLine("{0}的士兵用B表示", PlayerNames[1]);

            InitailMap();
            DrawMap();

            //玩家A和玩家B都没到终点，游戏继续
            while (PlayerPos[0] < 99 && PlayerPos[1] < 99)
            {
                Console.WriteLine("{0}按任意键开始掷骰子", PlayerNames[0]);
                Console.ReadKey(true);
                Console.WriteLine("{0}掷出了4", PlayerNames[0]);
                PlayerPos[0] += 4;
                Console.ReadKey(true);
                Console.WriteLine("{0}按任意键开始行动", PlayerNames[0]);
                Console.ReadKey(true);
                Console.WriteLine("{0}行动完了", PlayerNames[0]);
                Console.ReadKey(true);
                //玩家A有可能踩到了玩家B、方块、幸运轮盘、地雷、暂停、时空隧道
                if (PlayerPos[0] == PlayerPos[1])
                {
                    Console.WriteLine("玩家{0}踩到了玩家{1}，玩家{2}退6格", PlayerNames[0], PlayerNames[1], PlayerNames[1]);
                    PlayerPos[1] -= 6;
                    Console.ReadKey(true);
                }
                else//踩到关卡
                {
                    //玩家坐标

                    switch (Maps[PlayerPos[0]])//0 1 2 3 4
                    {
                        case 0:
                            Console.WriteLine("玩家{0}踩到了方块，安全", PlayerNames[0]);
                            Console.ReadKey(true);
                            break;
                        case 1:
                            Console.WriteLine("玩家{0}踩到了幸运轮盘，请选择：1--交换位置；2--轰炸对方退6格", PlayerNames[0]);
                            string input = Console.ReadLine();
                            Console.ReadKey(true);
                            break;
                    }
                }
            }

            Console.ReadKey();
        }

        /// <summary>
        /// 画游戏头
        /// </summary>
        public static void GameShow()
        {
            Console.ForegroundColor = ConsoleColor.DarkGreen;
            Console.WriteLine("*************************************************************");
            Console.ForegroundColor = ConsoleColor.DarkBlue;
            Console.WriteLine("*************************************************************");
            Console.ForegroundColor = ConsoleColor.Cyan;
            Console.WriteLine("*************************************************************");
            Console.ForegroundColor = ConsoleColor.Red;
            Console.WriteLine("**********************飞行棋游戏*****************************");
            Console.ForegroundColor = ConsoleColor.DarkGray;
            Console.WriteLine("*************************************************************");
            Console.ForegroundColor = ConsoleColor.Blue;
            Console.WriteLine("*************************************************************");
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("*************************************************************");
        }

        /// <summary>
        /// 初始化地图
        /// </summary>
        public static void InitailMap()
        {
            int[] luckyturn = { 6, 23, 40, 55, 69, 83 };//幸运轮盘○
            for (int i = 0; i < luckyturn.Length; i++)
            {
                Maps[luckyturn[i]] = 1;
            }

            int[] landMine = { 5, 13, 17, 33, 38, 50, 64, 80, 94 };//地雷☆
            for (int i = 0; i < landMine.Length; i++)
            {
                Maps[landMine[i]] = 2;
            }

            int[] pause = { 9, 27, 63, 93 };//暂停△
            for (int i = 0; i < pause.Length; i++)
            {
                Maps[pause[i]] = 3;
            }

            int[] timeTunnel = { 20, 25, 45, 63, 72, 88, 90 };//时空隧道##
            for (int i = 0; i < timeTunnel.Length; i++)
            {
                Maps[timeTunnel[i]] = 4;
            }
        }

        /// <summary>
        /// 画地图
        /// </summary>
        public static void DrawMap()
        {
            Console.WriteLine("图例：幸运轮盘：○    地雷：☆    暂停：△    时空隧道：##");

            //第一横行
            for (int i = 0; i < 30; i++)
            {
                Console.Write(DrowStringMap(i));
            }

            //画完第一横行后应该换行
            Console.WriteLine();

            //第一竖行
            for (int i = 30; i < 35; i++)
            {
                for (int j = 0; j <= 28; j++)
                {
                    Console.Write("  ");
                }
                Console.Write(DrowStringMap(i));
                Console.WriteLine();
            }

            //第一横行：倒序
            for (int i = 64; i >= 35; i--)
            {
                Console.Write(DrowStringMap(i));
            }

            //画完第二横行后应该换行
            Console.WriteLine();

            //第二竖行
            for (int i = 65; i <= 69; i++)
            {
                Console.WriteLine(DrowStringMap(i));
            }

            //第二横行
            for (int i = 70; i <= 99; i++)
            {
                Console.Write(DrowStringMap(i));
            }

            //画完最后一行应该换行
            Console.WriteLine();

        }

        /// <summary>
        /// 从画地图方法中抽象出来的方法
        /// </summary>
        /// <param name="i">地图中的位置</param>
        /// <returns>要打印的字符串</returns>
        public static string DrowStringMap(int i)
        {
            //声明str接收要打印的值
            string str = "";
            //玩家A和玩家B的坐标相同,并且都在地图上，则画<>
            if (PlayerPos[0] == PlayerPos[1] && PlayerPos[0] == i)
            {
                str = "<>";
            }
            else if (PlayerPos[0] == i)
            {
                str = "A";
            }
            else if (PlayerPos[1] == i)
            {
                str = "B";
            }
            else
            {
                switch (Maps[i])
                {
                    case 0:
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        str = "□";
                        break;
                    case 1:
                        Console.ForegroundColor = ConsoleColor.Green;
                        str = "○";
                        break;
                    case 2:
                        Console.ForegroundColor = ConsoleColor.Red;
                        str = "☆";
                        break;
                    case 3:
                        Console.ForegroundColor = ConsoleColor.Blue;
                        str = "△";
                        break;
                    case 4:
                        Console.ForegroundColor = ConsoleColor.DarkCyan;
                        str = "##";
                        break;
                }
            }

            return str;
        }


    }
}
